﻿@using Microsoft.AspNetCore.Mvc.Localization
@using Skoruba.IdentityServer4.Admin.BusinessLogic.Identity.Dtos.Grant
@using Skoruba.IdentityServer4.Admin.Helpers
@using Skoruba.IdentityServer4.Admin.BusinessLogic.Shared.Dtos.Common
@model PersistedGrantsDto
@inject IViewLocalizer Localizer

@{
	ViewBag.Title = Localizer["PageTitle"];
	Layout = "_Layout";
}

<div class="row">
	<div class="col-12">
		<nav aria-label="breadcrumb">
			<ol class="breadcrumb">
				<li class="breadcrumb-item"><a asp-controller="Grant" asp-action="PersistedGrants">@Localizer["NavigationPersistedGrants"]</a></li>
				<li class="breadcrumb-item active" aria-current="page">@Model.SubjectId</li>
			</ol>
		</nav>
	</div>

	<div class="col-12">
		<h2>@Localizer["PageTitle"]</h2>
	</div>
</div>

<form id="client-form" asp-controller="Grant" asp-action="PersistedGrantsDelete" Method="post">

	<a href="#" class="btn btn-danger mb-3" data-toggle="modal" data-target="#deletePersistedGrantsModal">@Localizer["ButtonDeleteAll"]</a>

	<!--Hidden -->
	<input type="hidden" asp-for="SubjectId" />

	<div class="row table-responsive">
		<div class="col-12">
			<table class="table table-striped">
				<thead>
                    <tr>
                        <th></th>
                        <th>@Localizer["TableSubjectId"]</th>
                        <th>@Localizer["TableType"]</th>
                        <th>@Localizer["TableExpiration"]</th>
                        <th>@Localizer["TableData"]</th>
                        <th>@Localizer["TableClient"]</th>
                    </tr>
				</thead>

				<tbody>
					@foreach (var persistedGrant in Model.PersistedGrants)
					{
                    <tr>
                        <td><a class="btn btn-danger" asp-action="PersistedGrantDelete" asp-route-id="@UrlHelpers.QueryStringSafeHash(persistedGrant.Key)"><span class="oi oi-x"></span></a></td>
                        <td>@persistedGrant.SubjectId</td>
                        <td>@persistedGrant.Type</td>
                        <td>@persistedGrant.Expiration</td>
                        <td>@persistedGrant.Data</td>
                        <td>@persistedGrant.ClientId</td>
                    </tr>
					}
				</tbody>
			</table>
		</div>
	</div>

	<div class="row">
		<div class="col-12">
			@await Html.PartialAsync("Common/Pager", new Pager { Action = "PersistedGrant", PageSize = Model.PageSize, TotalCount = Model.TotalCount })
		</div>
	</div>

	<!-- Modal -->
	<div class="modal fade" id="deletePersistedGrantsModal" tabindex="-1" role="dialog" aria-labelledby="deletePersistedGrantsModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<h4 class="modal-title" id="deletePersistedGrantsModalLabel">@Localizer["DeleteDialogTitle"]</h4>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				</div>
				<div class="modal-body">
					@Localizer["DeleteDialogMessage"]
				</div>
				<div class="modal-footer">
					<button type="submit" class="btn btn-danger">@Localizer["DeleteDialogYes"]</button>
					<button type="button" class="btn btn-outline-primary" data-dismiss="modal">@Localizer["DeleteDialogNo"]</button>
				</div>
			</div>
		</div>
	</div>
</form>